package Servlet;
 
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import Logic.SelectionLogic;
import Model.SelectionBean;
 
@SuppressWarnings("serial")
public class SelectionServlet extends HttpServlet {	
	 @Override
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {      
		 response.setCharacterEncoding("utf-8");
		 response.setContentType("text/html;charset=utf-8");
		 PrintWriter out = response.getWriter();
		 String opType = request.getParameter("opType");  
		 
	 }
	 
    // 接收客户端浏览器的POST请求，由Service方法跳转
    @Override
	public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
    	response.setCharacterEncoding("utf-8");
		 response.setContentType("text/html;charset=utf-8");
		 PrintWriter out = response.getWriter();
		 String opType = request.getParameter("opType");
		 
		if (opType.equals("addSelection")){	//新增/取消预定		 
			 String SelectionID = request.getParameter("SelectionID");
			 String SelectionMemberID = request.getParameter("SelectionMemberID");
			 String SelectionCurriculumID = request.getParameter("SelectionCurriculumID");
			 
			 String SelectionState = request.getParameter("SelectionState");
 
			 SelectionBean selectionbean = new SelectionBean();
			 selectionbean.setSelectionID(Integer.parseInt(SelectionID));
			 selectionbean.setSelectionMemberID(Integer.parseInt(SelectionMemberID));
			 selectionbean.setSelectionCurriculumID(Integer.parseInt(SelectionCurriculumID));
			 selectionbean.setSelectionState(Boolean.parseBoolean(SelectionState));
//TODO 根据State修改Curriculum数据库内的课程余量信息。并进行判断是否预定成功			 
			 SelectionLogic selectionlogic = new SelectionLogic();
			 selectionlogic.addSelection(selectionbean);
			 out.print(1);
		 }
    }
        
}

